package com.example.demo.controller.warehouse;


import com.example.demo.model.ResponseMessage;
import com.example.demo.model.warehouse.Warehouse;
import com.example.demo.service.warehouse.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService service;

    @RequestMapping("save")
    public ResponseMessage save(Warehouse warehouse) {
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = service.save(warehouse);
        responseMessage.setFlag(flag);

        return responseMessage;
    }

    //    查询全部
    @RequestMapping("selectAll")
    public List<Warehouse> selectAll() {
        return service.selectAll();
    }

    //    添加数据
    @RequestMapping("addWarehouse")
    public Integer addWarehouse(Warehouse warehouse) {
        return service.addWarehouse(warehouse);
    }

    //删除数据
    @RequestMapping("deleteById")
    public Boolean deleteById(Integer warehouse_id) {
        return service.deleteById(warehouse_id) == 1;
    }

    @RequestMapping("updateById")
    public Integer updateById(Warehouse warehouse) {
        return service.updateById(warehouse);
    }

    @RequestMapping("updateProductNumberById")
    public Integer updateProductNumberById(Integer number, Integer product_id) {
        return service.updateProductNumberById(number, product_id);
    }


    @RequestMapping("AddProductNumberById")
    Integer AddProductNumberById(Integer number, Integer product_id) {
        return service.AddProductNumberById(number, product_id);
    }

    @RequestMapping("findWarehouse")
    @ResponseBody
    public List<Warehouse> findWarehouse(Integer product_id, Integer provider_id) {
        return service.findWarehouse(product_id, provider_id);
    }

}
